package leetcode.weekly.week295;

//Solution3Test
public class Solution5 {

	// Solution3Test
	public int totalSteps(int[] nums) {
		int ans = 0;
		int last = 0;
		int i = 1;

		while (i < nums.length) {
			if (nums[i] < nums[last]) {
				int cnt = 0;
				// "[7,14,4,14,13,2,6,13]"
				while (i < nums.length && nums[i] < nums[last] && (i - 1 == last || nums[i] >= nums[i - 1])) {
					cnt++;
					i++;
				}
				ans = Math.max(ans, cnt);
			}
			if (i < nums.length) {
				if (nums[i] >= nums[i - 1]) {
					last = i;
					i++;
				}else {
					nums[i - 1] = -1;
				}
			}
		}
		return ans;
	}

}
